//
//  WBTabBar.m
//  sinaWeibo
//
//  Created by 李江波 on 2016/11/14.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

#import "WBTabBar.h"

@interface WBTabBar ()

@property(nonatomic ,strong) UIButton *btn;

@end

@implementation WBTabBar

-(instancetype)init{

    self = [super init];
    if (self) {
        
        _btn = [UIButton buttonWithType:0];
        [_btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [_btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [_btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:_btn];
        
    }
    return self;
}

-(void)btnClick{

    if (_btnClickBlock != nil) {
        
        _btnClickBlock();
    }
    
}


-(void)layoutSubviews{

    [super layoutSubviews];
    
//    NSLog(@"%@",self.subviews);
    
    CGFloat itemW = self.bounds.size.width / 5;
    CGFloat itemH = self.bounds.size.height;
    __block NSInteger index = 0;
    
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if ([obj isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            obj.frame = CGRectMake(index * itemW, 0, itemW, itemH);
            
            index += (index == 1) ? 2 : 1 ;
            
        }
        
    }];
    
    _btn.bounds = CGRectMake(0, 0, itemW, itemH);
    _btn.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.5);
    
    
}














@end
